public class Demo16 {
    public static void main(String[] args) {
        Object block1 = new Object();

        Object block2 = new Object();

        Thread thread1 = new Thread(()->{
            synchronized (block1) {
                System.out.println("thread1加block1");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (block2) {
                    System.out.println("thread1加block2");
                }
            }
        });
        Thread thread2 = new Thread(()->{
            synchronized (block2) {
                System.out.println("thread2加block1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (block1) {
                    System.out.println("thread1加block1");
                }
            }
        });
        thread1.start();
        thread2.start();
    }
}
